import qqmap from '../../../utils/qqmap'
Page({
  data: {
    latitude: 40.060539,
    longitude: 116.343847,
    // map地图标记点
    markers: [
      {
        id: 143323,
        latitude: 31.802824,
        longitude: 117.22995,
        while: 40,
        heigth: 40
      },
      {
        id: 143323,
        latitude: 31.812824,
        longitude: 117.21995,
        width: 40,
        heigth: 40
      }
    ],
    // map地图路线
    polyline: [
      {
        points: [
          { latitude: 31.802824, longitude: 117.21995 },
          { latitude: 31.862824, longitude: 117.26995 },
          { latitude: 31.812824, longitude: 117.23995 },
          { latitude: 31.842824, longitude: 117.21995 },
          { latitude: 31.892824, longitude: 117.25995 },
          { latitude: 31.802824, longitude: 117.21995 }
        ],
        // 线宽度
        width: 4,
        // 线颜色
        color: '#c04885',
        // 虚线
        dottedLine: true
      }
    ],
    houseInfo: '',
    id: '',
    houseId: '',
    repairItemName: '',
    repairItemId: '',
    mobile: '',
    appointment: '',
    description: '',
    attachment: [],
    status: 0
  },
  onLoad ({ id }) {
    this.getRepairList(id)
  },
  async getRepairList (id) {
    const res = await wx.http({ url: `/repair/${id}` })
    // console.log(res)
    this.setData({ ...res.data })
    // 地址解析
    this.geocoder()
  },
  geocoder () {
    // 地址解析
    qqmap.geocoder({
      address: '安徽省合肥市' + this.data.houseInfo,
      success: res => {
        // console.log(res)
        const { lat, lng } = res.result.location
        this.setData({ latitude: lat, longitude: lng })
      }
    })
  },
  goRepair () {
    wx.navigateTo({ url: '/repair_pkg/pages/form/index?id=' + this.data.id })
  },
  onCancel () {
    wx.showModal({
      title: '取消报修',
      content: '确定取消报修吗',
      success: async ({ confirm }) => {
        if (confirm) {
          wx.http({ url: `/cancel/repaire/${this.data.id}`, method: 'PUT' })

          wx.showToast({ title: '取消成功', icon: 'success' })

          setTimeout(() => {
            wx.navigateTo({ url: '/repair_pkg/pages/list/index' })
          }, 1500)
        }
      }
    })
  }
})
